import axios from '@/plugins/axios'
import utils from '@/plugins/utils'
import { Message } from 'element-ui'
export default {
  computeColor(asset_type) {
    let tintColor = ''
    switch (asset_type) {
      case 1:
        tintColor = '#6156e4'
        break
      case 2:
        tintColor = '#4fa8f9'
        break
      case 3:
        tintColor = '#bd5ee9'
        break
    }
    return tintColor
  },
  typeToRoute(asset_type) {
    let routeName = ''
    switch (asset_type) {
      case 1:
        routeName = 'market-tag'
        break
      case 2:
        routeName = 'market-tag'
        break
      case 3:
        routeName = 'market-album'
        break
    }
    return routeName
  },
  gotoDetail(item) {
    if (Number(item.asset_type) === 3 || Number(item.assetType) === 3) {
      axios({
        url: axios.setUrl(`ast/astAlbum/openPermission/${item.asset_id || item.assetId}`),
        method: 'get',
        params: axios.setParams()
      }).then(({ data }) => {
        if (data && data.code === '0') {
          if (data.data) {
            let routeName = this.typeToRoute(Number(item.asset_type || item.assetType))
            utils.blank(routeName, { params: { id: item.asset_id || item.assetId } })
          } else Message.error(`没有查看该专辑的权限`)
        } else {
          Message.error(data.data || data.msg)
        }
      })
    } else {
      if (!utils.isAuth('sch:astTag:view')) {
        this.$message.error(`没有查看标签的权限`)
        return
      }
      let routeName = this.typeToRoute(Number(item.asset_type || item.assetType))
      utils.blank(routeName, { params: { id: item.asset_id || item.assetId } })
    }
  }
}
